import { stringify } from 'qs';
import http from "~/utils/http";

export default {
  async query({topicId, page = 1, size = 20 }) {
    try {
      let { data } = await http.get(`/api/cms/comment?${stringify({topicId, page, size})}`)
      return data
    } catch (error) {
      return []
    }
  },
  
  async add({ topicId, topicType, content }) {
    try {
      let res = await http.post('/api/cms/comment', {
        topicId,
        topicType,
        content,
      })
      if (res.code === 0) {
        return res.data
      }
      else {
        Promise.reject({message: '评论失败'})
      }
    } catch (error) {
      Promise.reject({message: '评论失败'})
    }
  },

  async remove({ id }) {
    try {
      let { data } = await http.delete(`/api/cms/comment/${id}`)
      return data
    } catch (error) {
      Promise.reject({message: '删除失败'})
    }
  },
}